class Admin::CityController < Admin::ApplicationController
  def index
    @citys = City.where(:parent=>1)
    @second_citys = Array.new
    @three_citys = Array.new
    @citys.each_with_index do |city,index|
      @citys2 = City.where(:parent=>city[:id])
      @second_citys.push(@citys2)
      _citys3 = nil
      @citys2.each_with_index do |city2,index2|
        if _citys3 != nil
          _citys3 = _citys3 + City.where(:parent=>city2[:id])
        else
          _citys3 = City.where(:parent=>city2[:id])
        end
      end
      @three_citys.push(_citys3)
    end
  end

  def edit
    @city = City.find(params[:id])
    @city_message = ''
  end

  def show
    @city = City.find(params[:id])
    @city_message = ''
    render 'edit'
  end

  def update
    @city = City.find(params[:id])
    params[:description] = params[:description].strip
    @city.update( city_params )
    @city_message = '信息更新成功！'
    render 'edit'
  end

  private
  def city_params
    params.permit(:state, :address, :contact, :description)
  end

end
